#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <arpa/inet.h>
#include <ctype.h>
#include "wrap.h"
#define SERVER_PORT 6666
int main(int argc, char const *argv[])
{
        int lfd,cfd;
        struct sockaddr_in server_addr;
        struct sockaddr_in client_addr;
        socklen_t client_addr_len;
        char buf[BUFSIZ];
        int len;
        int i = 0;

        lfd = Socket(AF_INET,SOCK_STREAM,0);
        bzero(&server_addr,sizeof(server_addr));
        server_addr.sin_family = AF_INET;
        server_addr.sin_port = htons(SERVER_PORT);
        server_addr.sin_addr.s_addr = htonl(INADDR_ANY);
        Bind(lfd,(struct sockaddr *)&server_addr,sizeof(server_addr));

        Listen(lfd,128);

        client_addr_len = sizeof(client_addr);
        cfd = Accept(lfd,(struct sockaddr *)&client_addr,&client_addr_len);

        printAddr("client connect", &client_addr);

        while (1){
                len = Read(cfd,buf,sizeof(buf));
                for ( i = 0; i < len; i++){
                        buf[i] = toupper(buf[i]);
                }
                Write(cfd,buf,len);
        }
        Close(lfd);
        Close(cfd);
        return 0;
}


